/*
 * Command.h
 *
 *  Created on: 2011-11-18
 *      Author: kaishui
 */

#ifndef COMMAND_H_
#define COMMAND_H_


#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>


typedef enum {INIT=0,READY=1,MEASURE=2,PAUSE=3,DEBUG=4,ERROR=5} MStatus;
/*typedef unsigned short MStatus;
#define READY      0
#define MEASURE    1
#define PAUSE      2
#define DEBUG      3*/



#define ASK_ACCEPT 1
#define ASK_BUSY   2
#define ASK_ERROR  3


//测量命令
#define CMD_ASK              0x1   //状态查询
#define CMD_START_MEASURE    0x2   //开始测试
#define CMD_PAUSE_MEASURE    0x3   //暂停测试
#define CMD_STOP_MEASURE     0x4   //停止测试
#define CMD_SAMPLESHELF_OUT  0x5   //取样品架
#define CMD_REAGENT_OUT      0x6   //取试剂
#define CMD_SAMPLE_SCAN      0x7   //样品盘条码扫描
#define CMD_REAGENT_SCAN     0x8   //试剂盘条码扫描
#define CMD_REAGENT_CHANGE   0x9   //试剂量改变
#define CMD_RESULT           0xA   //完成一个测量
#define CMD_SAMPLE_ADD       0xB   //样本加样
#define CMD_CLEAR_CUP        0xC   //清杯命令
#define CMD_READ_CUP         0xD   //读空杯
#define CMD_READ_SUBSTRATE   0xE   //读底物
#define CMD_TIME_SYNC        0xF   //时钟同步
#define CMD_ALL_RESET        0x10  //全部设备复位
#define CMD_READ_SENSOR      0x11  //读传感器数据
#define CMD_READ_CAMERA      0x12  //读摄像头
#define CMD_LIGHT_INIT       0x13  //底物初始化
#define CMD_MACHINE_INIT     0x14  //仪器初始化
//#define CMD_LEFTNUM_SET      0x15  //剩余杯子数设置


//调试命令
//整机
#define CMD_UPDATE_ARM       0x101
#define CDM_UPDATE_PSOC      0x102
#define CMD_LED_TEST         0x103
#define CMD_OPEN_DATAPORT    0x104  //打开数据端口
#define CMD_RECYCLE_RESET    0x105  //重复复位某个部件测试

//样品手
#define CMD_SHAND_PICK       0x201  //样品手取样
#define CMD_SHAND_PUT        0x202  //样品手加样
#define CMD_SHAND_DOWN       0x203  //样品手下降步进
#define CMD_SHAND_WASH       0x204  //冲洗
#define CMD_SHAND_HRESET     0x205  //旋转（水平）复位
#define CMD_SHAND_VRESET     0x206  //垂直复位
#define CMD_SHAND_SYRESET    0x207  //注射器复位
#define CMD_SHAND_PIPINIT    0x208  //管路初始化
#define CMD_SHAND_RESET      0x209  //整体复位
#define CMD_SHAND_LEDTEST    0x20A  //点灯测试
#define CMD_SHAND_REBOOT     0x20B  //重启
#define CMD_SHAND_NULL       0x20C  //轮空
#define CMD_SHAND_VOLPARAM   0x20D  //设置加样量系数


//试剂手
#define CMD_RHAND_PICK       0x301  //样品手取样
#define CMD_RHAND_PUT        0x302  //样品手加样
#define CMD_RHAND_DOWN       0x303  //样品手下降步进
#define CMD_RHAND_WASH       0x304  //冲洗
#define CMD_RHAND_HRESET     0x305  //旋转（水平）复位
#define CMD_RHAND_VRESET     0x306  //垂直复位
#define CMD_RHAND_SYRESET    0x307  //注射器复位
#define CMD_RHAND_PIPINIT    0x308  //管路初始化
#define CMD_RHAND_RESET      0x309  //整体复位
#define CMD_RHAND_LEDTEST    0x30A  //点灯测试
#define CMD_RHAND_REBOOT     0x30B  //重启
#define CMD_RHAND_NULL       0x30C  //轮空
#define CMD_RHAND_VOLPARAM   0x30D  //设置加样量系数

//样品盘
#define CMD_SAMPLEDISK_READBARCODE 		0X401
#define CMD_SAMPLEDISK_ROTUEDISK		0X402

#define CMD_SAMPLEDISK_UNIT_RST			0x409
#define CMD_SAMPLEDISK_TEST_LED			0x40A
#define CMD_SAMPLEDISK_UNIT_REBOOT		0x40B

//试剂盘
#define CMD_REAGENTDISK_READBARCODE 	0X501
#define CMD_REAGENTDISK_ROTUEDISK		0X502

#define CMD_REAGENTDISK_UNIT_RST		0x509
#define CMD_REAGENTDISK_TEST_LED		0x50A
#define CMD_REAGENTDISK_UNIT_REBOOT		0x50B


//for rcu
#define CMD_RCU_R_GRID 					0x601
#define CMD_RCU_R_CIRCLE				0x602
#define CMD_RCU_RST						0x603
#define CMD_RCU_DANGGUANG_RST			0x604
#define CMD_RCU_DANGGUANG_SET			0x605
#define CMD_RCU_DROP_CUP_RST			0x606
#define CMD_RCU_DROP_CUP_SET			0x607

#define CMD_RCU_UNIT_RST				0x609
#define CMD_RCU_TEST_LED				0x60A
#define CMD_RCU_UNIT_REBOOT				0x60B
#define CMD_RCU_TEST_COMMUNICATION		0x60C
#define CMD_RCU_DO_NOTHING				0x60F

//清洗搅拌
#define CMD_WASHMIX_SUCK                0x701
#define CMD_WASHMIX_WASH                0x702
#define CMD_WASHMIX_INITWASH            0x703
#define CMD_WASHMIX_ADDLIGHT            0x704
#define CMD_WASHMIX_INITLIGHT           0x705
#define CMD_WASHMIX_MIX                 0x706
#define CMD_WASHMIX_RESET               0x707
#define CMD_WASHMIX_LEDTEST             0x708
#define CMD_WASHMIX_WHAND_RESET         0x709
#define CMD_WASHMIX_WHAND_DOWN          0x70A
#define CMD_WASHMIX_LSYRING_RESET       0x70B
#define CMD_WASHMIX_LSYRING_SUCK        0x70C
#define CMD_WASHMIX_LSYRING_PUT         0x70D
#define CMD_WASHMIX_WSYRING_RESET       0x70E
#define CMD_WASHMIX_WSYRING_SUCK        0x70F
#define CMD_WASHMIX_WSYRING_PUT         0x710
#define CMD_WASHMIX_PUMP_OPEN           0x711
#define CMD_WASHMIX_PUMP_CLOSE          0x712
#define CMD_WASHMIX_MIX_OPEN            0x713
#define CMD_WASHMIX_MIX_CLOSE           0x714


//for cupunit
#define CMD_CUP_CATCH_CUP				0x801
#define CMD_CUP_ADD_CUP					0x802
#define CMD_CUP_NEI_TO_ZHONG_SET		0x803
#define CMD_CUP_NEI_TO_ZHONG_RST		0x804
#define CMD_CUP_ZHONG_TO_WAI_SET		0x805
#define CMD_CUP_ZHONG_TO_WAI_RST		0x806
#define CMD_CUP_WAI_TO_ZHONG_SET		0x807
#define CMD_CUP_WAI_TO_ZHONG_RST		0x808

#define CMD_CUP_UNIT_RST				0x809
#define CMD_CUP_TEST_LED				0x80A
#define CMD_CUP_UNIT_REBOOT				0x80B
#define CMD_CUP_TEST_COMMUNICATION		0x80C
#define CMD_CUP_DO_NOTHING				0x80F

#define CMD_CUP_RECYCLE_TEST			0x810


//light
#define CMD_LIGHT_READ_LIGHT			0x901
#define CMD_LIGHT_COPYRESULT      		0x902  //
#define CMD_LIGHT_RECYCLE               0x903



#pragma pack(4)

class PC_Command
{
public:
	bool  bDebug; //是否调试命令
	unsigned short Command;  //命令动作
	unsigned short Depat;  //部件号
	unsigned short SubDep; //子设备  (ASK时指定试剂盘还是样品盘)
	unsigned int  Value;  //操作量
	unsigned short Reserver1;
	unsigned short Reserver2;
	unsigned short check;  //校验

	bool isCorrect();
	PC_Command& operator =(PC_Command &temp);
};//__attribute__((packed,aligned(4)));


class ARM_Command
{
public:
	unsigned char head;
	bool  bDebug; //是否调试命令
	unsigned short Status;  //状态  ，测量、暂停、就绪、调试
	unsigned short Command;  //响应的命令
	unsigned int   Error;     //错误码,0为正常
	unsigned short Depat;  //部件
	unsigned short SubDep; //子设备
	unsigned int pos;  //发生变化的位置
	unsigned short check;   //校验

	ARM_Command()
	{
		head=0xA;
		bDebug=false;
		Command=0;
		Error=0;
		Depat=0;
		SubDep=0;
		pos=0;
	}

	void CalcCheck();
};//__attribute__((packed,aligned(4)));

#pragma pack()

#endif /* COMMAND_H_ */
